home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / Miracle C Compiler / miricleC compiler.msi / Instal01.cab / _2362047B305649E0AFAA56319C68820D < prev    next >
Encoding:
Text File  |  2000-07-25  |  3.2 KB  |  162 lines

  1. // --- ctype.h testing program, written by bts 2/july/2000
  2.  
  3. #include <stdio.h>
  4. #include <ctype.h>
  5. #include <assert.h>
  6.  
  7. void xctype();
  8. int xct_punct(int c);
  9.  
  10. int main()
  11. {
  12.     xctype();
  13. }
  14.  
  15.  
  16. char    clist_isdigit[128],    clist_isupper[128],    clist_islower[128],    clist_isalpha[128],
  17.     clist_isalnum[128],    clist_isxdigit[128],    clist_ispunct[128],    clist_isprint[128],
  18.     clist_isgraph[128];
  19.  
  20. #define xct_add(clist,c)  { char *ptr=clist; while(*ptr++) ; *ptr='\0'; *--ptr=c; }
  21.  
  22. void xctype()
  23. {
  24.     int i;
  25.     char ibuf[20];
  26.  
  27.     printf("==> starting xctype <==\n");
  28.  
  29.     clist_isdigit[0]=clist_isupper[0]=clist_islower[0]=clist_isalpha[0]=
  30.     clist_isalnum[0]=clist_isxdigit[0]=clist_ispunct[0]=clist_isprint[0]=clist_isgraph[0]= '\0';
  31.  
  32.     for (i=0; i<=255; i++)
  33.         {
  34.         // --- check isdigit
  35.         if(i>='0' && i<='9')
  36.             {
  37.             assert(isdigit(i));
  38.             xct_add(clist_isdigit,i);
  39.             }
  40.         else
  41.             assert(!isdigit(i));
  42.  
  43.         // --- check isupper
  44.         if(i>='A' && i<='Z')
  45.             {
  46.             assert(isupper(i));
  47.             xct_add(clist_isupper,i);
  48.             }
  49.         else
  50.             assert(!isupper(i));
  51.  
  52.         // --- check islower
  53.         if(i>='a' && i<='z')
  54.             {
  55.             assert(islower(i));
  56.             xct_add(clist_islower,i);
  57.             }
  58.         else
  59.             assert(!islower(i));
  60.  
  61.         // --- check isalpha
  62.         if(isupper(i) || islower(i))
  63.             {
  64.             assert(isalpha(i));
  65.             xct_add(clist_isalpha,i);
  66.             }
  67.         else
  68.             assert(!isalpha(i));
  69.  
  70.         // --- check isalnum
  71.         if(isupper(i) || islower(i) || isdigit(i))
  72.             {
  73.             assert(isalnum(i));
  74.             xct_add(clist_isalnum,i);
  75.             }
  76.         else
  77.             assert(!isalnum(i));
  78.  
  79.         // --- check isxdigit
  80.         if(isdigit(i) || (i>='a' && i<='f') || (i>='A' && i<='F'))
  81.             {
  82.             assert(isxdigit(i));
  83.             xct_add(clist_isxdigit,i);
  84.             }
  85.         else
  86.             assert(!isxdigit(i));
  87.  
  88.         // --- check isspace, can be 9-13 or 32
  89.         if((i>=9 && i<=13) || i==32)
  90.             assert(isspace(i));
  91.         else
  92.             assert(!isspace(i));
  93.  
  94.         // --- check iscntrl, can be 0-31 or 127
  95.         if((i>=0 && i<=31) || i==127)
  96.             assert(iscntrl(i));
  97.         else
  98.             assert(!iscntrl(i));
  99.  
  100.         // --- check ispunct
  101.         if(xct_punct(i))
  102.             {
  103.             assert(ispunct(i));
  104.             xct_add(clist_ispunct,i);
  105.             }
  106.         else
  107.             assert(!ispunct(i));
  108.  
  109.         // --- check isgraph
  110.         if(isalnum(i) || ispunct(i))
  111.             {
  112.             assert(isgraph(i));
  113.             xct_add(clist_isgraph,i);
  114.             }
  115.         else
  116.             assert(!isgraph(i));
  117.  
  118.         // --- check isascii
  119.         if(i<0x80)
  120.             assert(isascii(i));
  121.         else
  122.             assert(!isascii(i));
  123.  
  124.         // --- check isprint
  125.         if(isgraph(i) || i==32)
  126.             {
  127.             assert(isprint(i));
  128.             xct_add(clist_isprint,i);
  129.             }
  130.         else
  131.             assert(!isprint(i));
  132.         }
  133.  
  134.     printf("isdigit:\t%s\n",clist_isdigit);
  135.     printf("isupper:\t%s\n",clist_isupper);
  136.     printf("islower:\t%s\n",clist_islower);
  137.     printf("isalpha:\t%s\n",clist_isalpha);
  138.  
  139.     printf("isalnum:\t%s\n",clist_isalnum);
  140.     printf("isxdigit:\t%s\n",clist_isxdigit);
  141.     printf("ispunct:\t%s\n",clist_ispunct);
  142.  
  143.     printf("isgraph:\t%s\n",clist_isgraph);
  144.     printf("isprint:\t%s\n",clist_isprint);
  145.  
  146.     printf("==> finished xctype <==\n");
  147.     return;
  148. }
  149.  
  150. int xct_punct(int c)
  151. {
  152.     // --- punc[] is an exhaustive list of all ascii punctuation characters
  153.     char punc[] = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
  154.     int i;
  155.  
  156.     for(i=0; punc[i]; i++)
  157.         if(punc[i]==c)
  158.             return 1;
  159.  
  160.     return 0;
  161. }
  162.